package com.itheima.dao;

import com.itheima.domain.Teacher;

/*
老师  数据操作类
数组

增 
删
改  
查
 */
public class TeacherDao {
    private static Teacher[] teachers= new Teacher[10];
    //增
    public boolean addTeacher(Teacher teacher){
        for (int i = 0; i < teachers.length; i++) {
            Teacher tea = teachers[i];
            if(tea==null){
                teachers[i]=teacher;
                return true;
            }
        }
        return false;
    }

    //删
    public void deleteTeacher(String sid){
        int index = getIndex(sid);
        teachers[index]=null;
    }

    //改
    public void updateTeacher(String sid,Teacher teacher){
        int index = getIndex(sid);
        teachers[index]=teacher;
    }
    //查
    public Teacher[] findAllTeachers(){
        return teachers;
    }
    //根据工号 找索引
    public  int getIndex(String sid){

        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if(teacher!=null&&teacher.getSid().equals(sid)){
                return i;
            }
        }
        return -1;
    }

}
